<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>setup与渲染函数一起使用</title>
</head>

<body>
    <div id="app">
        <input type="button" value="修改作者" @click="changeAuthor">
        <book ref="child"></book>
    </div>
</body>
<script src="./js/vue.global.js"></script>
<script>

    const { createApp, ref, onMounted,h } = Vue

    // 子组件
    let book = {
        setup(props, context) {

            function handle01(){
                console.log("handle01");
            }

            context.expose({
                handle01
            })
            
            const count = ref(250);
            const changeCount = ()=>{
                count.value++;
            }
            
            // setup函数里返回渲染函数的调用结果，那么就是该组件的目标
            return ()=>h("p",{"id":"p01","onClick":changeCount},"我是个p："+count.value);

            
        }
    }


    const app = createApp({
        components: { book },
        setup(){

            const child = ref();

            onMounted(()=>{
                child.value.handle01();
            })

            return {
                child
            }

        }
    })



    app.mount('#app')
</script>

</html>